import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-09-15
 * Time: 11:58
 */
class KthLargest {
    PriorityQueue<Integer> heap;
    int _k;
    public KthLargest(int k, int[] nums) {
        _k = k;
        heap = new PriorityQueue<>();

        for(int x : nums) {
            heap.offer(x);
            if(heap.size() > _k) {
                heap.poll();
            }
        }
    }

    public int add(int val) {
        heap.offer(val);
        if(heap.size() > _k) {
            heap.poll();
        }
        return heap.peek();
    }
}
